 <template>
    <div>
        <div id="wordView" v-html="vHtml" />
    </div>
</template>

<script>
import mammoth from "mammoth";
export default {
    name: "word",
    data() {
        return {
            vHtml: "",
            wordURL: "", //文件地址
        };
    },
    created() {
        let vm = this;
        vm.wordURL = "http://localhost/dev-api/common/download?fileName=/profile/upload/2021/03/29/000b83ee-0fb1-46a6-8d15-addaa9bd5b7f.docx&delete=false";
        const xhr = new XMLHttpRequest();
        xhr.open("get", this.wordURL, true);
        xhr.responseType = "arraybuffer";
        xhr.onload = function () {
            if (xhr.status == 200) {
                mammoth
                    .convertToHtml({
                        arrayBuffer: new Uint8Array(xhr.response),
                    })
                    .then(function (resultObject) {
                       vm.vHtml =resultObject.value;
                    });
            }
        };
        xhr.send();
    },
    methods: {},
};
</script>

<style>
</style>
